import { ApiResult } from 'src/config';
import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
} from '@nestjs/common';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { CarBrandService } from './car_brand.service';
import { CreateCarBrandDto } from './dto/create-car_brand.dto';
import { UpdateCarBrandDto } from './dto/update-car_brand.dto';
import { FindAllCarBrandDto } from './dto/findAll-car_brand.dto';

@ApiTags('汽车品牌')
@Controller('car-brand')
export class CarBrandController {
  constructor(private readonly carBrandService: CarBrandService) {}

  @ApiOperation({ summary: '创建汽车品牌' })
  @Post()
  async create(
    @Body() createCarBrandDto: CreateCarBrandDto,
  ): Promise<ApiResult> {
    const result = await this.carBrandService.create(createCarBrandDto);
    return ApiResult.SUCCESS(result, 0, '创建成功!');
  }

  @ApiOperation({ summary: '获取所有汽车品牌' })
  @Get()
  async findAll(
    @Query() findAllCarBrandDto: FindAllCarBrandDto,
  ): Promise<ApiResult> {
    const result = await this.carBrandService.findAll(findAllCarBrandDto);
    return ApiResult.SUCCESS(result, 0, '获取成功！');
  }

  @ApiOperation({ summary: '获取所有汽车品牌' })
  @Get('findAllCarType')
  async findAllCarType(): Promise<ApiResult> {
    const result = await this.carBrandService.findAllCarType();
    return ApiResult.SUCCESS(result, 0, '获取成功！');
  }

  @ApiOperation({ summary: '根据id获取汽车品牌' })
  @Get(':id')
  async findOne(@Param('id') id: string): Promise<ApiResult> {
    const result = await this.carBrandService.findOne(+id);
    return ApiResult.SUCCESS(result, 0, '获取成功！');
  }
  
  @ApiOperation({ summary: '根据id修改汽车品牌信息' })
  @Patch(':id')
  async update(
    @Param('id') id: string,
    @Body() updateCarBrandDto: UpdateCarBrandDto,
  ): Promise<ApiResult> {
    const result = await this.carBrandService.update(+id, updateCarBrandDto);
    return ApiResult.SUCCESS(result, 0, '修改成功!');
  }

  @ApiOperation({ summary: '删除汽车品牌' })
  @Delete(':id')
  async remove(@Param('id') id: string): Promise<ApiResult> {
    const result = await this.carBrandService.remove(+id);
    return ApiResult.SUCCESS(result, 0, '删除成功!');
  }
}
